package com.qing.seckill.service.impl;

import com.alibaba.fastjson.JSON;
import com.qing.seckill.entity.TbSeckillGoods;
import com.qing.seckill.mapper.TbSeckillGoodsMapper;
import com.qing.seckill.result.Result;
import com.qing.seckill.service.ITbSeckillGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhipeng.cao
 * @since 2021-04-19
 */
@Service
public class TbSeckillGoodsServiceImpl extends ServiceImpl<TbSeckillGoodsMapper, TbSeckillGoods> implements ITbSeckillGoodsService {


	@Autowired
	private StringRedisTemplate redisTemplate;

	@Override
	public TbSeckillGoods detail(Long id) {
		//获取商品详情
		TbSeckillGoods seckillGoods = JSON.parseObject((String) redisTemplate.boundHashOps(TbSeckillGoods.class.getSimpleName()).get(String.valueOf(id)), TbSeckillGoods.class);
		if (Objects.isNull(seckillGoods)) {
			throw new RuntimeException("已售罄！");
		}
		return seckillGoods;
	}
}
